package JUC.Thread;

/**
 * @program: jvm
 * @description  守护线程针对于用户线程  用户线程终止 守护线程随机终止
 * @author: tkk fendoukaoziji
 * @create: 2019-03-13 14:22
 **/
public class Daemon {
    public static class DaeMonT extends Thread{
        public void run(){
            while(true){
                System.out.println("i am alive");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        DaeMonT t = new DaeMonT();
       t.setDaemon(true);//设置守护线程  主线程终止时，守护线程随机停止   如果不设置守护线程会一直运行
        t.start();
        Thread.sleep(2000);
    }
}
